/**
 * Created by SangYang on 2022-1-10.
 * 封装本地缓存
 */
export default {
  save(key: string, data: any) {
    sessionStorage.setItem(key, JSON.stringify(data))
  },
  get(key: string, defaultValue: any = null) {
    const item = sessionStorage.getItem(key)
    return item ? JSON.parse(item) : defaultValue
  },
  remove(key: string) {
    console.log('remove', key);
    sessionStorage.removeItem(key)
  },
  clear() {
    sessionStorage.clear()
  },
  _saveLocal(key: string, data: any) {
    localStorage.setItem(key, JSON.stringify(data))
  },
  _getLocal(key: string, defaultValue = null) {
    const item = localStorage.getItem(key)
    return item ? JSON.parse(item) : defaultValue
  },
  _removeLocal(key: string) {
    localStorage.removeItem(key)
  },
  _clearLocal() {
    localStorage.clear()
  }
}
